package com.ruoyi.web.controller.agoniapp;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@Slf4j
@RequestMapping({"/agoniapp/upload","/upload"})
public class Upload {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    @PostMapping("/uploadImage")
    public AjaxResult uploadImage(@RequestParam("image") MultipartFile file) {

        //创建图片对象


        try {
            String url = aliOSSUtils.upload(file);
            return AjaxResult.success("上传成功", url);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
}
